package br.uefs.ecomp.myBook.view;

import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseListener;

import javax.swing.JTextField;

public class GenericTextField extends JTextField implements FocusListener{
	
	private String originalText;
	
	public GenericTextField(String originalText){
		super(originalText);
		this.originalText = originalText;
		this.setFont(new Font("Arial", Font.ITALIC, 12));
		this.addFocusListener(this);
	}
	
	@Override 
	public String getText(){
		String k = super.getText();
		if(k.equals(originalText))
			return "";
		else 
			return k;
	}

	@Override
	public void focusGained(FocusEvent e) {
		if(getText().equals(""))
			this.setText("");
		this.setFont(new Font("Arial", Font.PLAIN, 12));
	}

	@Override
	public void focusLost(FocusEvent e) {
		if(super.getText().equals("")){
			this.setText(originalText);
			this.setFont(new Font("Arial", Font.ITALIC, 12));
		}
	}

}
